﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ColorSweet : MonoBehaviour
{
   public enum ColorType//颜色种类
    {
        BLUE,
        YELLOW,
        RED,
        PURPLE,
        GREEN,
        PINK,
        ANY,
        COUNT
    }
    private Dictionary<ColorType, Sprite> colorSpriteDict;
    [System.Serializable]
    public struct ColorSprite
    {
        public ColorType color;
        public Sprite sprite;
    }
    public ColorSprite[] colorSprites;
    private SpriteRenderer sprite;
    //颜色数组的长度
    public int NumClolrs
    {
        get => colorSprites.Length;
    }
    //颜色
    public ColorType Color
    {
        get => color;
        set => SetColor(value);
    }

    private ColorType color;
    public void SetColor(ColorType newcolor)
    {
        color = newcolor;
        if(colorSpriteDict.ContainsKey(newcolor))
        {
            sprite.sprite = colorSpriteDict[newcolor];
        }
    }
    private void Awake()
    {
        sprite = transform.Find("Blue").GetComponent<SpriteRenderer>();
        colorSpriteDict = new Dictionary<ColorType, Sprite>();
        //添加没有的甜品
        for(int index=0;index<colorSprites.Length;index++)
        {
            if (!colorSpriteDict.ContainsKey(colorSprites[index].color))
            {
                colorSpriteDict.Add(colorSprites[index].color, colorSprites[index].sprite);
            }
        }
    }

}
